<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <script type="text/javascript" src="../script/config.js"></script>
    <style>
        header{ background-color: #f16c3c; line-height: 42px; height: 42px; position: relative;padding-top:22px;}
        header b{ width: 42px; height:42px; display: inline-block; position: relative; z-index: 1; background: url() no-repeat center; background-size: 70% auto;  }
        header b.ic-back{ background-image: url(../image/back.png);background-size:25px 25px;}
        /*header b.ic-check{ background-image: url(../image/ic-check.png); float: right; }*/
        header .title{ position: absolute; left: 0; bottom: 0; right: 0;  text-align: center; font-size: 18px;color:white;}
        #foot{
          position:relative;;
          margin:0 auto;
          width:90%;
          height:120px;
          bottom:0;
          left:0;
          font-size:18px;
        }
        .foot_sure{
          /*padding-left:17%;
          padding-right:17%;
          padding-top:10px;
          padding-bottom:10px;*/
          background-color:#f16c3c;
          width:80%;
          height:40px;
          color:white;
          border-radius:10px;
          text-align:center;
          margin:0 auto;
          line-height:40px;
          margin-top:25px;
        }
        .foot_cancle{
          padding-left:17%;
          padding-right:17%;
          padding-top:10px;
          padding-bottom:10px;
          background-color:#f16c3c;
          color:white;
          border-radius:10px;
        }
        .duigou{
          vertical-align:middle;
          line-height:20px;
          height:20px;
          text-align:center;
          margin-top:15px;
        }
        .duigou>img{
          height:20px;
          vertical-align:middle;
        }
        .rights_obligations{
           text-decoration: underline;
           color:blue;
           line-height:20px;
           height:20px;
        }
    </style>
</head>
<body>
    <div id="wrap" class="flex-wrap flex-vertical" >
        <header class="border-b" >
            <b tapmode="hover" onclick="api.closeWin();" class="ic-back"></b>
            <div class="title" id="title"></div>
            <!-- <b tapmode="hover" onclick="funActionSheet();"  class="ic-check"></b> -->
        </header>
        <div id="main" class="flex-con" >

        </div>
        <div id="foot">
            <div class="duigou"><img src="../image/duigou1.png" id="duigou_img"/><span class="rights_obligations">甲乙双方权利与义务</span></div>
            <div class="foot_sure" id="foot_sure"></div>
            <!-- <span class="foot_cancle" id="foot_cancle">取消</span> -->
        </div>
    </div>
</body>
</html>
<script type="text/javascript" src="../script/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<!-- <script type="text/javascript" src="../script/up_check.js"></script> -->
<script type="text/javascript">
    apiready = function(){
      api.addEventListener({
                            name:'viewappear'
                        }, function(ret, err){
                           api.setScreenOrientation({
                            orientation: 'portrait_up'
                        });
                        });
        var agreement_id=api.pageParam.agreement_id;
      $api.text($api.dom("#title"),'合同详情');
      $api.get(url+'app.php/agreement_status?agreement_id='+agreement_id,function(ret){
       if(ret.result==0){
          if(ret.agreement.agreement_status==0){
             $api.text($api.dom('#foot_sure'),'签字');
             $api.addEvt($api.dom("#duigou_img"),'click',function(){
               if($api.attr($api.dom('#duigou_img'),'src')=='../image/duigou1.png'){
                  $api.attr($api.dom('#duigou_img'),'src','../image/duigou2.png');
                  $api.css($api.dom('#foot_sure'),'background-color:#999999;');
               }else{
                  $api.attr($api.dom('#duigou_img'),'src','../image/duigou1.png');
                  $api.css($api.dom('#foot_sure'),'background-color:#f16c3c;');
               }

             });
          }else{
            $api.text($api.dom('#foot_sure'),'确认');
          }
       }
     },'json');

     $api.addEvt($api.dom(".rights_obligations"),'click',function(){
       api.openFrame({
           name: 'details',
           url: './details.html',
           bounces:false,
           rect: {
               x: 0,
               y: $api.dom('header').offsetHeight,
               w: api.winWidth,
               h: api.winHeight-$api.dom('header').offsetHeight
           },
     });
     });


        api.openFrame({
            name: 'agreement_one',
            url: './agreement_one.html',
            rect: {
                x: 0,
                y: $api.dom('header').offsetHeight,
                w: api.winWidth,
                h: $api.dom('#main').offsetHeight
            },
            pageParam: {
                  agreement_id:agreement_id
                    }
});
$api.addEvt($api.dom("#foot_sure"), 'click', function(){
  var sign=$api.text($api.dom('#foot_sure'));
  if(sign=='签字'&&($api.attr($api.dom('#duigou_img'),'src')=='../image/duigou1.png')){
    api.openWin({
        name: 'agreement_sign',
        url: './agreement_sign.html',
        slidBackEnabled:false,
        pageParam: {
              agreement_id:agreement_id
                }
});
  }else if(sign=='签字'&&($api.attr($api.dom('#duigou_img'),'src')=='../image/duigou2.png')){


  }else{
    setTimeout("api.closeWin({name:'my_agreement'})",550);
    setTimeout("api.closeWin({name:'agreement_one_main'})",600);
    setTimeout("api.openWin({name:'main',url:'../main.html',})",650);
  }

  var user = $api.getStorage('user');
  var lorryid=user.lorryid;
  var time=user.time;
  check(lorryid,time);
});
$api.addEvt($api.dom("#foot_cancle"), 'click', function(){
  var scheduling_id=api.pageParam.scheduling_id;
  var user = $api.getStorage('user');
  var lorryid=user.lorryid;
  api.closeWin();
  var time=user.time;
  check(lorryid,time);
});

}
var upload_map=function(id){
  // alert(1)
  var bMap = api.require('bMap');
  bMap.getLocation({
      accuracy: '10m',
      autoStop: true,
      filter: 1
  }, function(ret, err) {
      if (ret.status) {
        $api.post(url+'app.php/scmap',{
         body:{
              lorryid:id,
              longitude:ret.lon,
              latitude:ret.lat,
              }
         },function(ret){
        //  alert(ret.desc);
       },'json');
      } else {
          // alert(err.code);
      }
  });
}
var check=function(id,time){
  $api.post(url+'app.php/check',{
        body:{lorryid:id,
              time:time,}
       },function(ret){
        if(ret.result==4){
          alert(ret.desc);
          api.openWin({
            name: 'index',
            url:  '../index.html',
          });
           setTimeout("api.closeWin({name:'main'})",650);
           $api.rmStorage('password');
           var key = 'user';
           var user = {};
           var aa=$api.getStorage(key);
           user.lorryid=aa.lorryid;
            user.telephone=aa.telephone;
           user.flag= aa.flag
           user.pass= '';
           $api.setStorage(key, user);
           api.alert({
             title: '提示消息',
             msg: ret.desc,
             buttons: ['确定']
           });
         }else{
          //  alert(ret.desc);
         }
       });
}
</script>
